package cn.mdmbct.douyin.common.proxy.invoker;

import java.lang.invoke.MethodHandle;
import java.lang.reflect.Method;

/**
 * @author mdmbct  mdmbct@outlook.com
 * @date 5/10/2021 11:57 AM
 * @modified mdmbct
 * @since 1.0
 */
public class DefaultServiceMethodInvoker<T> implements ServiceMethodInvoker<T> {

    private final MethodHandle methodHandle;

    public DefaultServiceMethodInvoker(MethodHandle methodHandle) {
        this.methodHandle = methodHandle;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return methodHandle.bindTo(proxy).invokeWithArguments(args);
    }
}
